package com.rabbiter.hospital.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MyBatisPlusConfig {
    /**
     * 注册插件
     * @return MybatisPlusInterceptor 返回配置好的 MybatisPlusInterceptor 实例
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        // 创建 MybatisPlusInterceptor 实例
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        // 添加分页插件
        PaginationInnerInterceptor pageInterceptor = new PaginationInnerInterceptor();
        // 设置数据库类型为 MySQL
        pageInterceptor.setDbType(DbType.MYSQL);
        // 将分页插件添加到拦截器中
        interceptor.addInnerInterceptor(pageInterceptor);
        // 创建乐观锁插件实例
        OptimisticLockerInnerInterceptor optimisticLockerInnerInterceptor = new OptimisticLockerInnerInterceptor();
        // 将乐观锁插件添加到拦截器中
        interceptor.addInnerInterceptor(optimisticLockerInnerInterceptor);
        // 返回配置好的 MybatisPlusInterceptor 实例
        return interceptor;
    }
}
